﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Forms;

namespace ImaginationFactory.Dialogs
{
    /// <summary>
    /// ContrastDialog.xaml 的交互逻辑
    /// </summary>
    public partial class ContrastDialog : Window
    {

        static MainWindow mWindowTemp;
        static MainListBox mListBox;
        static int lightAndShadeTemp;
        static int contrastValue;
        

        public ContrastDialog( MainWindow mWindow )
        {
            InitializeComponent();
            mWindowTemp = mWindow;

            lightAndShadeScr.Value = 0;
            contrastScr.Value = 0;
            lightAndShadeTemp = 0;
            contrastValue = 0;

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if ( lightAndShadeTemp != 0 )
              mWindowTemp.ImageLibrary.IntensityAdjustment(lightAndShadeTemp);
            if ( contrastValue != 0 )
                mWindowTemp.ImageLibrary.ColorConstrast( 1.0 + contrastValue / 100.0 );
           
            mWindowTemp.image.Source = mWindowTemp.ImageLibrary.LoadedImage.Source;
            lightAndShadeScr.Value = 0;
            lightAndShadeScr.Value = 0;
            this.Close();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void ContrastDlg_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();
        }


        private void lightAndShadeScr_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if ( -100 <= lightAndShadeScr.Value  && lightAndShadeScr.Value <= 100)
            {
                lightAndShadeTemp = Convert.ToInt32(lightAndShadeScr.Value);
                //在合理范围内
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("请输入-100 -- 100的数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);                
            } 
        }

        private void contrastScr_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if ( -100 <= contrastScr.Value  && contrastScr.Value <= 100 )
            {
                contrastValue = Convert.ToInt32( contrastScr.Value );
                //在合理范围内
            }
            else
            {
                System.Windows.Forms.MessageBox.Show( "请输入-100 -- 100的数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error );
            } 
        }
    }
}
